//
//  FSWEmptyView.m
//  TuanLife
//
//  Created by WuJianMac on 2018/1/13.
//  Copyright © 2018年 HuiNaMac. All rights reserved.
//

#import "FSWEmptyView.h"

@interface FSWEmptyView()

@property (weak, nonatomic) IBOutlet UIImageView *imageView;
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
@property (nonatomic, copy) clickLoadingBlock block;
@property (nonatomic, copy) clickAddButtonBlock addBlock;
@property (weak, nonatomic) IBOutlet XCBaseButton *loadButton;
@property (weak, nonatomic) IBOutlet UIButton *addButton;

@end

@implementation FSWEmptyView
-(void)awakeFromNib{
    [super awakeFromNib];
//    self.loadButton.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.4];
}
#pragma mark - Responder Method

- (IBAction)addButton:(id)sender {
    if (self.addBlock) {
        self.addBlock();
    }
}
- (IBAction)clickAction:(id)sender {
    if(self.block){
        self.block();
    }
}

#pragma mark - Private Method
- (void)type:(FSWEmptyType)type andShowButton:(BOOL)is_show andMsg:(NSString *)msg andBlock:(clickLoadingBlock)block andAddButtonBlock:(clickAddButtonBlock)addBlock
{
    self.block = block;
    self.addBlock = addBlock;
    self.addButton.hidden = YES;
    switch (type) {
            case NoData:
            self.loadButton.hidden = YES;
            self.imageView.image = [UIImage imageNamed:@"no_data"];
            self.titleLabel.text = msg;
            break;
            case NoAddress:
            self.loadButton.hidden = YES;
            self.addButton.hidden = NO;
            self.imageView.image = [UIImage imageNamed:@"address_null_icon"];
            self.titleLabel.text = @"您还没有添加地址";
            break;
            case NoOrder:
            self.loadButton.hidden = YES;
            self.imageView.image = [UIImage imageNamed:@"order_null_icon"];
            self.titleLabel.text = @"您没有相关订单";
            break;
            case ServiceError:
            self.loadButton.hidden = YES;
             self.addButton.hidden = NO;
            self.imageView.image = [UIImage imageNamed:@"not_net"];
            self.titleLabel.text = @"对不起，请求出错啦";
            break;
            case NoCar:
            self.loadButton.hidden = YES;
            self.imageView.image = [UIImage imageNamed:@"详情_购物车无-38"];
            self.titleLabel.text = @"您的购物车是空的，快去挑选您的商品吧！";
            break;
            
        default:
            self.loadButton.hidden = YES;
             self.addButton.hidden = NO;
            self.imageView.image = [UIImage imageNamed:@"no_net"];
            self.titleLabel.text = @"亲！网络连接失败";
            break;
    }
    self.addButton.hidden = !is_show;
}

#pragma mark - Public Method
+ (void)hiddenView:(UIView*)superView
{
    for (UIView* view in superView.subviews) {
        if ([view isKindOfClass:[FSWEmptyView class]]) {
            [view removeFromSuperview];
            return;
        }
    }
}
+ (void)show:(FSWEmptyType)type andShowButton:(BOOL)is_show andMsg:(NSString *)msg andSuperView:(UIView*)superView andBlock:(clickLoadingBlock)block andAddButtonBlock:(clickAddButtonBlock)addBlock{
    
    for (UIView* view in superView.subviews) {
        if ([view isKindOfClass:[FSWEmptyView class]]) {
            [view removeFromSuperview];
        }
    }
    
    FSWEmptyView* emptyview = (FSWEmptyView*)[[NSBundle mainBundle] loadNibNamed:@"FSWEmptyView" owner:nil options:nil].firstObject;
    emptyview.frame = superView.bounds;
    [emptyview type:type andShowButton:is_show andMsg:msg andBlock:block andAddButtonBlock:addBlock];
    [superView insertSubview:emptyview atIndex:0];
    [emptyview bringOneLevelUp];
}

@end
